import * as logService from "../../services/log";

export default {
    namespace: 'log',
    state: {
      logList : [],
      logItem:{},
      currentItem : {},
      current : 1,
      currentSize : 10,
      total : 0, 
      modalVisible : false,
      newKey : '',
    },
    reducers: {
        queryListSuc(state, { payload }) {
            return { ...state, ...payload};
        },
        showViewModal(state,{payload}){
            return{...state,...payload,viewModalVisible: true}
        },
        hideViewModal (state) {
            return { ...state, viewModalVisible: false, }
        },
    },
    effects: {
      *qryById({payload},{ call, put }){
        const { body }  = yield call(logService.qryById,payload);
        yield put({type: 'showViewModal',payload:{currentItem:body.data},});
      },

      *qryList({ payload },{ call, put }) {
        const { body } = yield call(logService.qryList,payload);
        yield put({ type: 'queryListSuc', payload: { logList:body.data, current:body.current, currentSize:body.size, total:body.iTotalRecords}});
      },
    },
    subscriptions: {
      setup({ dispatch, history }) {
        return history.listen(({ pathname }) => {
          if (pathname === '/sys/log') {
            dispatch({ type: 'qryList', payload:{'userName':''}});
          }
        });
      },
    },
  };